/**
 * Created by Fly on 2016/9/12.
 */
var DBPool=require('../util/DBpool');
module.exports= {
    add:function (_title,_content,_icon,req,res,callback){
        console.log('_____________________________________');
        var user=req.session.userID;
        var title=_title;
        var date=new Date();
        console.log(date);
        console.log('查看user'+user);
        var icon=_icon;
        var content=_content;
        var sql="INSERT INTO t_article(title,date,content,userno,icon)VALUES(?,?,?,?,?)";
        DBPool.getConnection(function (client) {
            client.query('SELECT userno FROM t_userinfo WHERE username=?',[user],function (error,result) {
                if(error){
                    console.log(error.message);
                    return;
                }
                console.log("得到的result的结果是"+JSON.stringify(result));
                console.log("得到的result的结果是"+result[0].userno);
                var _userno=result[0].userno;
                client.query(sql,[title,date,content,_userno,icon],function (error,result) {
                    if(error){
                        console.log(error.message);
                        return;
                    }
                    callback(result);
                    client.release();
                });
            });
        });
    }


};
